<?php

class Cities_Table_Creator {

    public $cities_table_name;
    public $estate_name_column_name;
    public $city_name_column_name;
    public $id_name_column_name;
    
    public function __construct($cities_table_name, $estate_name_column_name, $city_name_column_name, $id_name_column_name) {
        $this->cities_table_name = $cities_table_name;
        $this->estate_name_column_name = $estate_name_column_name;
        $this->city_name_column_name = $city_name_column_name;
        $this->id_name_column_name = $id_name_column_name;
    }
    
    public function create_cities_table($connection) {
        if ($connection == FALSE) {
            return FALSE;
        }
        
        $drop_table_sql = 'DROP TABLE IF EXISTS ' . $this->cities_table_name;
        $drop_success = mysql_query($drop_table_sql, $connection);
        
        $create_table_sql = "CREATE TABLE {$this->cities_table_name} (
            {$this->id_name_column_name} int not null auto_increment,
            {$this->estate_name_column_name} char(2) not null default '',
            {$this->city_name_column_name} varchar(128) not null default '',
            primary key({$this->id_name_column_name}),
            index({$this->estate_name_column_name})) engine=InnoDB";
        return mysql_query($create_table_sql, $connection);
    }

}

?>
